package com.hzp.lolnews.ui.novel.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.hzp.lolnews.R;
import com.hzp.lolnews.ui.novel.bean.NovelBean;
import com.hzp.lolnews.ui.novel.view.DetailWenActivity;

import java.util.List;

/**
 * Created by Administrator on 10/20 0020.
 */
public class NovelAdapter extends RecyclerView.Adapter<NovelAdapter.MyViewHolder>{
    private List<NovelBean> mList;
    private Context mContext;

    public NovelAdapter(Context context) {
        this.mContext = context;
    }
    public void setData(List<NovelBean> list) {
        this.mList = list;
        notifyDataSetChanged();
    }
    public void setMoreData(List<NovelBean> list){
        mList.addAll(list);
        notifyDataSetChanged();
    }


    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.novel_two_list_item, null, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, final int position) {
        final NovelBean bean = mList.get(position);
        String novel_article_referrals = bean.getArticle_referrals();
        String novel_share_title_other = bean.getShare_title_other();
        String novel_article_recommend = bean.getArticle_recommend();
        String novel_article_love_count = bean.getArticle_love_count();
        String novel_article_format_date = bean.getArticle_format_date();
        String novel_article_avator = bean.getArticle_avatar();
        String novel_article_pic = bean.getArticle_pic();
        holder.novel_article_referrals.setText(novel_article_referrals);
        holder.novel_share_title_other.setText(novel_share_title_other);
        holder.novel_article_recommend.setText(novel_article_recommend);
        holder.novel_article_love_count.setText(novel_article_love_count);
        holder.novel_article_format_date.setText(novel_article_format_date);
        holder.novel_article_avator.setImageURI(novel_article_avator);
        holder.novel_article_pic.setImageURI(novel_article_pic);
        holder.novel_article_pic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext, DetailWenActivity.class);
                intent.putExtra("getArticle_pic",bean.getArticle_pic());
                intent.putExtra("getArticle_type_name",bean.getArticle_type_name());
                intent.putExtra("getArticle_format_date",bean.getArticle_format_date());
                intent.putExtra("getArticle_title",bean.getArticle_title());
                intent.putExtra("getArticle_filter_content",bean.getArticle_filter_content());
                mContext.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {
        return mList != null ? mList.size() : 0;
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        private TextView novel_article_referrals,novel_share_title_other,novel_article_recommend,novel_article_love_count,novel_article_format_date;
        private SimpleDraweeView novel_article_avator,novel_article_pic;

        public MyViewHolder(View itemView) {
            super(itemView);
            novel_article_avator = (SimpleDraweeView) itemView.findViewById(R.id.novel_article_avator);
            novel_article_pic = (SimpleDraweeView) itemView.findViewById(R.id.novel_article_pic);
            novel_article_referrals = (TextView) itemView.findViewById(R.id.novel_article_referrals);
            novel_share_title_other = (TextView) itemView.findViewById(R.id.novel_share_title_other);
            novel_article_recommend = (TextView) itemView.findViewById(R.id.novel_article_recommend);
            novel_article_love_count = (TextView) itemView.findViewById(R.id.novel_article_love_count);
            novel_article_format_date = (TextView) itemView.findViewById(R.id.novel_article_format_date);
        }
    }
}
